package com.md.client.helper;

import com.fasterxml.jackson.core.type.TypeReference;
import com.md.api.OpenSystemApi;
import com.md.base.BaseClient;
import com.md.model.system.BaseOpenController;
import com.md.model.system.CommonResult;
import com.md.request.ApiRequest;
import com.md.request.AppInfoRequest;
import com.md.request.BatchIdRequest;
import com.md.request.QueryAppInfoRequest;
import com.md.request.QueryModuleRequest;
import com.md.response.ApiResponse;
import com.md.response.AppInfoResponse;
import com.md.response.ModuleResponse;

import java.util.List;

/**
 * @author 刘骄阳
 * 2024-10-11 15:05
 */
public class DefaultOpenSystemApiController extends BaseOpenController implements OpenSystemApi {

  public DefaultOpenSystemApiController(final BaseClient baseClient,
                                        final String endpoint) {
    super(baseClient, endpoint, "system-center", "/apps/system" + PATH_PREFIX);
  }

  @Override
  public CommonResult<AppInfoResponse> openQuery(final QueryAppInfoRequest request) {
    return checkResponse(getBaseClient().post(buildPostUrl("/app-info/query"), request,
      new TypeReference<CommonResult<AppInfoResponse>>() {
      }));
  }

  @Override
  public CommonResult<List<AppInfoResponse>> openQueryList(final QueryAppInfoRequest request) {
    return checkResponse(getBaseClient().post(buildPostUrl("/app-info/query/list"), request,
      new TypeReference<CommonResult<List<AppInfoResponse>>>() {
      }));
  }

  @Override
  public CommonResult<List<AppInfoResponse>> openQueryIdsList(final BatchIdRequest request) {
    return checkResponse(getBaseClient().post(buildPostUrl("/app-info/query/list/ids"), request,
      new TypeReference<CommonResult<List<AppInfoResponse>>>() {
      }));
  }

  @Override
  public CommonResult<Void> openCreateAppInfo(final AppInfoRequest request) {
    return checkResponse(getBaseClient().post(buildPostUrl("/app-info/create"), request,
      new TypeReference<CommonResult<Void>>() {
      }));
  }

  @Override
  public CommonResult<Void> openCreateApi(final ApiRequest request) {
    return checkResponse(getBaseClient().post(buildPostUrl("/api/create"), request,
      new TypeReference<CommonResult<Void>>() {
      }));
  }

  @Override
  public CommonResult<List<ModuleResponse>> openQueryList(final QueryModuleRequest request) {
    return checkResponse(getBaseClient().post(buildPostUrl("/module/query/list"), request,
      new TypeReference<CommonResult<List<ModuleResponse>>>() {
      }));
  }

  @Override
  public CommonResult<ApiResponse> openQuery(final ApiRequest request) {
    return checkResponse(getBaseClient().post(buildPostUrl("/api/query"), request,
      new TypeReference<CommonResult<ApiResponse>>() {
      }));
  }

  @Override
  public CommonResult<ApiResponse> openQueryByUrlMethod(final ApiRequest request) {
    return checkResponse(getBaseClient().post(buildPostUrl("/api/query-method-url"), request,
      new TypeReference<CommonResult<ApiResponse>>() {
      }));
  }

  @Override
  public CommonResult<List<ApiResponse>> openQueryList(final ApiRequest request) {
    return checkResponse(getBaseClient().post(buildPostUrl("/api/query/list"), request,
      new TypeReference<CommonResult<List<ApiResponse>>>() {
      }));
  }

  @Override
  public CommonResult<List<ModuleResponse>> openQueryListByIdList(final QueryModuleRequest request) {
    return checkResponse(getBaseClient().post(buildPostUrl("/module/query/list-by-ids"), request,
      new TypeReference<CommonResult<List<ModuleResponse>>>() {
      }));
  }

  @Override
  public CommonResult<List<AppInfoResponse>> openQueryListByModuleId(final QueryAppInfoRequest request) {
    return checkResponse(getBaseClient().post(buildPostUrl("/app-info/query/list-module-id"), request,
      new TypeReference<CommonResult<List<AppInfoResponse>>>() {
      }));
  }
}
